﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Panel.Master" Inherits="System.Web.Mvc.ViewPage<IList<Prodma.DataAccess.Models.ViewModels.UnitVm>>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	<%=System.Configuration.ConfigurationManager.AppSettings["pageTitle"] %>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <div class="listHeader">
        <img src="../../Images/ListImages/unitlist.png" alt="" class="listHeaderIco" />
        <div class="listHeaderText">Birim Yöneticisi</div>
        
        <div class="listHeaderMenuBox">
            <% Html.RenderPartial("/views/shared/userControls/navigation.ascx",
                   Prodma.DataAccess.Authorization.Authorization.GetNavigation("unit", 19));%>
        </div>
    </div>
    
    <div class="listFindBar">
        <% Html.RenderPartial("/views/shared/userControls/find.ascx",
               new Prodma.DataAccess.Models.UserControlViewModels.FindVm() { View = "unit" });%>
    </div>
    
    <div class="listTitleContainer">
        <div class="listTitleCenter-50">#</div>
        <div class="listTitleCenter-50"><input type="checkbox" id="chk" name="chk" /></div>
        <div class="listTitleLeft-200">Ad</div>
        <div class="listTitleCenter-150">Durum</div>
        <div class="listTitleCenter-50">ID</div>
    </div>
    
    <div class="listRowContainer">
    <!-- Set ParentMenu & SubMenu -->
    <% List<Prodma.DataAccess.Models.ViewModels.UnitVm> parentItems = new List<Prodma.DataAccess.Models.ViewModels.UnitVm>(); %>
    <% List<Prodma.DataAccess.Models.ViewModels.UnitVm> subItems = new List<Prodma.DataAccess.Models.ViewModels.UnitVm>(); %>
    <% for (int i = 0; i < ViewData.Model.Count; i++) %>
    <% { %>
         <% for (int j = 0; j < ViewData.Model.Count; j++)%>
         <% { %>
              <% if (ViewData.Model[i].Id == ViewData.Model[j].Parent.Id) %>
              <% { %>
                   <% ViewData.Model[i].SubItemCount++; %>
              <% } %>
         <% } %>
         
         <% if (ViewData.Model[i].Parent.Id == 0) %>
         <% { %>
              <% parentItems.Add(ViewData.Model[i]); %>
         <% } %>
         <% else %>
         <% { %>
              <% subItems.Add(ViewData.Model[i]); %>
         <% } %>
    <% } %>
    <!--***************************-->
    <% int counter = 0; %>
    <% foreach (Prodma.DataAccess.Models.ViewModels.UnitVm parent in parentItems) %>
    <% { %>
         <% counter++; %>
         <!-- List of Parent Menu -->
         <% if (counter % 2 != 0) %>
         <% { %>
              <div class="listRow1">
                  <div class="listColumnCenter-50"><%=counter%></div>                      
                  <div class="listColumnCenter-50"><input type="checkbox" id='chk<%=parent.Id %>' name="chkSelect" /></div>
                  <div class="listColumnLeft-200">
                    <a href='/unit/edit/?id=<%=parent.Id %>' class="listSelectItemBold">
                        <%=parent.Name%>
                    </a>
                  </div>
                  <div class="listColumnCenter-150"><%=parent.State.Name%></div>
                  <div class="listColumnCenter-50"><%=parent.Id%></div>
              </div>
         <% } %>
         <% else %>
         <% { %>
              <div class="listRow2">
                  <div class="listColumnCenter-50"><%=counter%></div>                      
                  <div class="listColumnCenter-50"><input type="checkbox" id='chk<%=parent.Id %>' name="chkSelect" /></div>
                  <div class="listColumnLeft-200">
                    <a href='/unit/edit/?id=<%=parent.Id %>' class="listSelectItemBold">
                        <%=parent.Name%>
                    </a>
                  </div>
                  <div class="listColumnCenter-150"><%=parent.State.Name%></div>
                  <div class="listColumnCenter-50"><%=parent.Id%></div>
              </div>
          <% } %>
          <!-- List of Sub Menu -->
          <% foreach (Prodma.DataAccess.Models.ViewModels.UnitVm sub in subItems) %>
          <% { %>
               <% if (parent.Id == sub.Parent.Id) %>
               <% { %>
                    <% counter++; %>
                    <% if (counter % 2 != 0) %>
                    <% { %>
                        <div class="listRow1">
                          <div class="listColumnCenter-50"><%=counter %></div>                      
                          <div class="listColumnCenter-50"><input type="checkbox" id='chk<%=sub.Id %>' name="chkSelect" /></div>
                          <div class="listColumnLeft-200">
                            -----<a href='/unit/edit/?id=<%=sub.Id %>' class="listSelectItemNormal">
                                <%=sub.Name%>
                            </a>
                          </div>
                          <div class="listColumnCenter-150"><%=sub.State.Name%></div>
                          <div class="listColumnCenter-50"><%=sub.Id%></div>
                      </div>
                  <% } %>
                  <% else %>
                  <% { %>
                      <div class="listRow2">
                          <div class="listColumnCenter-50"><%=counter %></div>                      
                          <div class="listColumnCenter-50"><input type="checkbox" id='chk<%=sub.Id %>' name="chkSelect" /></div>
                          <div class="listColumnLeft-200">
                            -----<a href='/unit/edit/?id=<%=sub.Id %>' class="listSelectItemNormal">
                                <%=sub.Name%>
                            </a>
                          </div>
                          <div class="listColumnCenter-150"><%=sub.State.Name%></div>
                          <div class="listColumnCenter-50"><%=sub.Id%></div>
                      </div>
                   <% } %>
              <% } %>
         <% } %>
    <% } %>
    </div>

    <script type="text/javascript">
        $(function() {
            $('#chk').click(function() {
                $("input[type='checkbox']").attr('checked', $('#chk').is(':checked'));
            });
        });
    </script>

</asp:Content>
